﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace LiteExpress.Core.DbClient
{
    /// <summary>
    /// 
    /// </summary>
    public class DataBase
    {
        Regex rgx = new Regex(@"((Initial Catalog)|(database))\=([^\;]+)\;", RegexOptions.IgnoreCase| RegexOptions.Compiled);

        /// <summary>
        /// 连接串名称譬如CoreUser
        /// </summary>
        public string ConnectionName { get; set; }

        /// <summary>
        /// 数据库真实名称，从连接串获取
        /// </summary>
        public string DbName { get
            {
                
                var match = rgx.Match(this.ConnectionString);

                if(match.Success && match.Groups.Count >4)
                {
                    var ret = match.Groups[4].Value;
                    return ret;
                }                
                return string.Empty;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string ConnectionString { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public DataBaseType DBType { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public bool Pooling { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int MaxPoolSize { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int MinPoolSize { get; set; }


        public string ProviderName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        internal DataBase()
        {
        }
    }
}
